package DP;

/**
 * @author 曹见朋
 * @create 2024-06-16-22:12
 */
public class Main392 {
    // TODO 392. 判断子序列
    public static boolean isSubsequence(String s, String t) {
        int s_len = s.length();
        int t_len = t.length();

        int[][] dp = new int[s_len + 1][t_len + 1];

        for(int i = 1; i <= s_len; i++){
            for(int j = 1; j <= t_len; j++){
                if(s.charAt(i - 1) == t.charAt(j - 1)){
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                }else{
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i][j -1]);
                }
            }
        }
        return dp[s_len][t_len] == s_len;
    }

    public static void main(String[] args) {
        String s = "axc";
        String t = "ahbgdc";
        System.out.println(isSubsequence(s, t));
    }
}
